import QtQuick 2.15
import QtQuick.Controls 2.15
import Backend 1.0

Item {
    // 是否处于展示状态
    property bool isShow: false

    id: cm
    x: parent.width
    // 展出状态占总窗口大小一半
    width: parent.width / 2 + 10
    height: parent.height

    Rectangle {
        color: "gray"
        width: 10
        height: parent.height
        Label {
            text: "<"
            font.pixelSize: 10
            color: "white"
            anchors.centerIn: parent
        }
    }

    ApplicationView {
        id: appview
        // 全局应用状态
        mtype: AppDataModel.FULL
        anchors.fill: parent
    }

    // 动画隐藏/展示菜单
    function showChoiceMenu() {
        if (isShow) {
            animiOutView.running = true;
            animiOutBtn.running = true;
            animiOut.running = true;
        }else {
            animInView.running = true;
            animInBtn.running = true;
            animIn.running = true;
        }
    }

    // 当动画结束时，更新状态
    Connections {
        target: animIn
        function onStopped() {
            isShow = true
        }
    }
    Connections {
        target: animiOut
        function onStopped() {
            isShow = false
        }
    }

    NumberAnimation {
        id: animIn
        target: cm
        property: "x"
        from: parent.width
        to: parent.width - cm.width
        duration: 1500
        easing.type: Easing.InOutExpo
    }

    NumberAnimation {
        id: animInView
        target: mainMenu
        property: "width"
        from: mainMenu.width
        to: mainMenu.width - cm.width
        duration: 1500
        easing.type: Easing.InOutExpo
    }

    NumberAnimation {
        id: animInBtn
        target: menuShowBtn
        property: "x"
        from: menuShowBtn.x
        to: menuShowBtn.x - cm.width
        duration: 1500
        easing.type: Easing.InOutExpo
    }

    NumberAnimation {
        id: animiOut
        target: cm;
        property: "x"
        from: parent.width - cm.width
        to: parent.width
        duration: 1500
        easing.type: Easing.InOutExpo
    }

    NumberAnimation {
        id: animiOutView
        target: mainMenu
        property: "width"
        from: mainMenu.width
        to: mainMenu.width + cm.width
        duration: 1500
        easing.type: Easing.InOutExpo
    }

    NumberAnimation {
        id: animiOutBtn
        target: menuShowBtn
        property: "x"
        from: menuShowBtn.x
        to: menuShowBtn.x + cm.width
        duration: 1500
        easing.type: Easing.InOutExpo
    }
}
